// license-header java merge-point
/**
 * This is only generated once! It will never be overwritten.
 * You can (and have to!) safely modify it by hand.
 * TEMPLATE:    SpringServiceImpl.vsl in andromda-spring cartridge
 * MODEL CLASS: tsaditiro::com.systemsjr.tsaditiro::user::service::UserService
 * STEREOTYPE:  Service
 */
package com.systemsjr.tsaditiro.user.service;

import com.systemsjr.tsaditiro.user.User;
import com.systemsjr.tsaditiro.user.vo.UserSearchCriteria;
import com.systemsjr.tsaditiro.user.vo.UserVO;

import java.util.List;

/**
 * @see com.systemsjr.tsaditiro.user.service.UserService
 */
public class UserServiceImpl
    extends UserServiceBase
{

    /**
     * @see com.systemsjr.tsaditiro.user.service.UserService#saveUser(UserVO)
     */
    protected  UserVO handleSaveUser(UserVO userVO)
        throws Exception
    {
    	User user = getUserDao().userVOToEntity(userVO);
    	
    	if(userVO.getId() != null){
    		getUserDao().update(user);
    	} else{
    		user = getUserDao().create(user);
    	}
    	
    	return getUserDao().toUserVO(user);
    }

    /**
     * @see com.systemsjr.tsaditiro.user.service.UserService#deleteUser(UserVO)
     */
    protected  void handleDeleteUser(UserVO userVO)
        throws Exception
    {
    	if(userVO.getId() != null){
    		getUserDao().remove(userVO.getId());
    	}
    }

    /**
     * @see com.systemsjr.tsaditiro.user.service.UserService#loadAll()
     */
    protected  List handleLoadAll()
        throws Exception
    {
    	List l = (List) getUserDao().loadAll();
    	
    	return (List) getUserDao().toUserVOCollection(l);
    }

    /**
     * @see com.systemsjr.tsaditiro.user.service.UserService#searchUsers(UserSearchCriteria)
     */
    protected  List<UserVO> handleSearchUsers(UserSearchCriteria searchCriteria)
        throws Exception
    {
    	List l = getUserDao().findByCriteria(searchCriteria);
    	
    	return (List) getUserDao().toUserVOCollection(l);
    }

}